@/*
    表单中SelectTreeCon框标签中各个参数的说明:
    id : input框id
    name : input框名称
    value : value
    textValue :textValue
    url : 树地址
    isMulti : 是否多选
@*/
@if(isNotEmpty(widgetParam)){
	@var _wpMap = {};
	@var _tmpLs = strutil.split(widgetParam,",");
	@for(ele in _tmpLs){
		@var _ele = strutil.split(ele,"=");
		@_wpMap[_ele[0]]=_ele[1];
	@}
    @textValue = _wpMap["textValue"];
    @url = _wpMap["url"];
    @isMulti = _wpMap["isMulti"];
@}
<div class="form-group">
    @if(!isEmpty(name)){
    <label for="${id}" class="control-label">${name}</label>
    @}
    <input type="hidden" id="${id}" name="${id}" value="${value!}"/>
    <input class="textbox" id="${id}_text" name="${id}_text" value="${textValue!}" style="width: 153px;"/>
</div>
<script type="text/javascript">
	var ${id}_load_url = "${backendPath}${url!}";
    $("#${id}_text").click(function(){
    	var ids = $("#${id}").val();
    	var opt = {
                type: 2,
                title: '选择${name!}',
                area: ['300px', '450px'], //宽高
                fix: false, //不固定
                maxmin: true,
                content: '/static/common/_selecttree.html',
                success: function(layero, index){
                    var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                    iframeWin.initTree(${id}_load_url,${isMulti!false},ids);
                }
            }
		opt["btn"]=[];
    	opt.btn.push('<i class="fa fa-check"></i> 确定');
    	opt['btn'+opt.btn.length] = function(index, layero){
            var win = window[layero.find('iframe')[0]['name']];
			win.$('#keyword').val('').change();
			var codes = [], names = [], nodes;
			if (${isMulti!false}){
				nodes = win.tree.getCheckedNodes(true);
			}else{
				nodes = win.tree.getSelectedNodes();
			}
			for(var i=0; i<nodes.length; i++) {
				if (nodes[i].level == 0 && nodes[i].isParent){
					Sys.info("不能选择根节点（"+nodes[i].name+"）请重新选择。");
					return false;
				}
				var code = (nodes[i].value || nodes[i].id)+"", name = nodes[i].name;
				codes.push(code.replace(/^u_/g,''));
				names.push(name.replace(/\([0-9]*\)/g,''));
			}
			$("#${id}").val(codes.join(',')).change();
			$("#${id}_text").val(names.join(',')).change();
            layer.close(index);
    	};

    	opt.btn.push('<i class="fa fa-eraser"></i> 清除');
    	opt['btn'+opt.btn.length] = function(index, layero){
    		$("#${id}").val('').change();
    		$("#${id}_text").val('').change();
    	};

    	opt.btn.push('<i class="fa fa-close"></i> 关闭');
    	opt['btn'+opt.btn.length] = function(index, layero){
            var index = layer.getFrameIndex(layero.find('iframe')[0]['name']); //获取窗口索引
            layer.close(index);
    	};

        layer.open(opt);
    });
</script>
